package com.rfchina.okr.xianren.task;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.rfchina.okr.xianren.manager.MyMoneyManager;
import com.rfchina.okr.xianren.model.RechargeInfo;
import com.rfchina.okr.xianren.model.WithdrawInfo;
import com.rfchina.okr.xianren.util.MoneyObjectType;

public class TaskRechargeInfo implements Runnable {

	private static Logger logger = LoggerFactory.getLogger(TaskRechargeInfo.class);

	@Override
	public void run() {

		String sql = "select * from recharge_info where status=1 order by id limit 1";
		List<RechargeInfo> list = RechargeInfo.dao.find(sql);
		for (RechargeInfo info : list) {
			Date lockTime = new Date();
			Long uid = info.getUid();
			Integer id = info.getId();
			String appid = info.getAppid();
			BigDecimal money = info.getAmount();
			String billAuditComment = "定时任务增加金币";
			int flow = MyMoneyManager.getInstance().changeMoney(lockTime, uid, id, appid, money, billAuditComment,
					MoneyObjectType.recharge);
			logger.info("flow:{},info:{},lockTime{}", flow, info, lockTime);
		}

		sql = "select * from withdraw_info where status=1 order by id limit 1";
		List<WithdrawInfo> list1 = WithdrawInfo.dao.find(sql);
		for (WithdrawInfo info : list1) {
			Date lockTime = new Date();
			Long uid = info.getUid();
			Integer id = info.getId();
			String appid = info.getAppid();
			BigDecimal money = info.getAmount().multiply(BigDecimal.valueOf(-1L));
			String billAuditComment = "定时任务提现";
			int flow = MyMoneyManager.getInstance().changeMoney(lockTime, uid, id, appid, money, billAuditComment,
					MoneyObjectType.withdraw);
			logger.info("flow:{},info:{},lockTime{}", flow, info, lockTime);
		}

	}

}
